package semaphore;

import java.util.concurrent.Semaphore;

/**
 * Created by 5406160@qq.com on LiBoWen 李博闻.
 *
 * @ClassName : Demo
 * @Author : 54061
 * @Date: 2022/2/17 9:50
 */
public class Demo {
    public static void main(String[] args) {
        //创建一个任务对象

    }
}
class MyRunnable implements Runnable{
    //获得管理员对象
    private Semaphore semaphore = new Semaphore(2);
    @Override
    public void run() {
        //活得通行证
        try {
            semaphore.acquire();
            //开始行驶
        System.out.println(Thread.currentThread().getName()+"活得了通行证开始通行");
        Thread.sleep(1000);
            System.out.println(Thread.currentThread().getName()+"归还通行证");
            //归还通行证
        semaphore.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}